using System.Web.UI;
using Quiki.ExpressionParsers;

namespace Quiki.ElementFormatters
{
    public class SimpleElementFormatter : ElementFormatterBase
    {
        public SimpleElementFormatter(WikiTextElementType elementType, int? level, HtmlTextWriterTag htmlTag)
        {
            this.elementType = elementType;
            this.level = level;
            this.htmlTag = htmlTag;
        }

        public SimpleElementFormatter (WikiTextElementType elementType, HtmlTextWriterTag htmlTag)
        {
            this.elementType = elementType;
            this.htmlTag = htmlTag;
        }

        public override bool FormatBegin (WikiTextElement element, HtmlFormatterContext context)
        {
            if (element.ElementType == elementType && element.Level == level)
            {
                context.Writer.RenderBeginTag(htmlTag);
                return true;
            }

            return false;
        }

        public override void FormatEnd (WikiTextElement element, HtmlFormatterContext context)
        {
            if (element.ElementType == elementType && element.Level == level)
            {
                context.Writer.RenderEndTag ();
                return;
            }
        }

        private readonly WikiTextElementType elementType;
        private readonly int? level;
        private readonly HtmlTextWriterTag htmlTag;
    }
}